package com.wangrui.controller;


import com.wangrui.pojo.Semester;
import com.wangrui.service.SemesterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * <p>
 *  学期管理
 * </p>
 *
 * @author 王锐
 * @since 2020-07-05
 */
@Controller
@RequestMapping("/semester")
public class SemesterController {
    @Autowired
    private SemesterService semesterService;
    /**
    * @Description: 跳转学期管理页面
    * @Param: []
    * @return: java.lang.String
    * @Author: 王锐
    * @Date:  2020/7/9 13:43
    */
    @RequestMapping("/semesterList")
    public String semesterListHtml()  {
        return "semester/semesterList";
    }

    @RequestMapping("/save")
    public String saveHtml()  {
        return "semester/save";
    }

    @RequestMapping("/update")
    public String updateHtml()  {
        return "semester/update";
    }

    @RequestMapping("/queryAllSemesters")
    public ResponseEntity<Map<String, Object>> queryAllSemesters(
            @RequestParam("page")int start,
            @RequestParam("rows")int end
    ) {
        Map<String, Object> stringObjectMap = semesterService.AllSemesters(start, end);

        stringObjectMap.put("total",semesterService.getTotal()) ;
        return ResponseEntity.ok(stringObjectMap);
    }

    @RequestMapping("/semesterSave")
    public ResponseEntity<Void> semesterSave(Semester semester)  {
        semesterService.semesterSave(semester);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/semesterUpdate")
    public ResponseEntity<Void> semesterUpdate(Semester semester)  {
        semesterService.semesterUpdate(semester);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/semesterDelete")
    @ResponseBody
    public String semesterDelete(int  ids)  {
        semesterService.semesterDelete(ids);
        return "ok";
    }

}

